package cn.crawler.framework.filter;

import cn.crawler.framework.util.IPTableUtil;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Lang;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.ActionContext;
import org.nutz.mvc.ActionFilter;
import org.nutz.mvc.View;

@IocBean(singleton = false)
public class IPTablesFilter implements ActionFilter {
    private static final Log log = Logs.get();

    @Override
    public View match(ActionContext actionContext) {
        if (actionContext.getIoc().get(IPTableUtil.class).contains(Lang.getIP(actionContext.getRequest()))) {
            return (req, resp, obj) -> resp.setStatus(403);
        }
        //正常处理下一调用链环节
        return null;
    }
}
